<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<!--动态设置每个div的宽高,让其等于当前页面的宽高,让背景色随机生成,并且定时滚动到下一页-->
<div></div>
<div></div>
<div></div>
<div></div>
<script>
  window.onload = function (ev) {

    // 创建变量存放获取的当前屏幕的宽高
    var w = window.innerWidth;
    var h = window.innerHeight;
    // 找到所有的div
    var alldiv = document.getElementsByTagName("div");

    for (var i = 0; i < alldiv.length; i++) {
      // 把获取到的当前屏幕的宽高赋给所有的div的宽高
      alldiv[i].style.width = w + "px";
      alldiv[i].style.height = h + "px";

      // 随机色
      var arr = ["0", "1", "2","3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
      var allcolor = "";
      for (var k = 0; k < 6; k++) {
        // 创建0-15随机数作为arr的下标,arr有16条数据
        var num = parseInt(Math.random() * 16);
        // 0<=Math.random()<1
        allcolor += arr[num];
      }
      // 把生成的随机色赋给所有的div
      alldiv[i].style.backgroundColor = "#" + allcolor;
      console.log("#" + allcolor);
    }
    var neww = 0;
    var newh = 0;
    setInterval(function () {
      w = window.innerWidth;
      h = window.innerHeight;
      neww += w;
      newh += h;
      window.scroll(neww, newh);
    }, 1000)
  }
</script>
</body>
</html>
